import { getSonMenu, menuPage, sysPage } from '@/api/appPlatfor';
import { orgAll } from '@/api/basic';
import { defineStore } from 'pinia';

export const useStore = defineStore('home', {
    state: () => ({
        menuList: [],
        functionList: [],
        menuData: [],
        orgallData: [],
        sysPageData: [],
        userInfo: {
            fullname: '',
            avatar: ''
        },
        menulist: JSON.parse(sessionStorage.getItem("menuList")) || []
    }),
    getters: {
        set_func_flag(name) {
            let menulist = JSON.parse(sessionStorage.getItem('menuList'))
            console.log(menulist);
            console.log(name);
            return true

        }
    },
    actions: {
        //获取机构
        async getOrgAll() {
            const res = await orgAll({});
            if (res.code === 200) {
                this.orgallData = res.data
            }
        },
        //获取平台
        async getSysPage() {
            const res = await sysPage();
            if (res.code === 200) {
                this.sysPageData = res.data.data
            }
        },
        //获取菜单
        async getMenuData() {
            const res = await menuPage()
            if (res.code === 200) {
                this.menuData = res.data.data
                this.menuData.forEach(async item => {
                    const child = await this.getSonMenuData(item.id)
                    item.children = child.data
                })
            }
        },
        //获取子菜单
        async getSonMenuData(id) {
            const res = await getSonMenu({ id: id })
            return res
        },
    },
})